package com.example.book_system.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.book_system.common.Result;
import com.example.book_system.entity.Book;
import com.example.book_system.entity.ReadHistory;
import com.example.book_system.entity.Reader;
import com.example.book_system.service.ReaderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author BlueRose
 */
@RestController
@RequestMapping("/api/reader")
public class ReaderController {

    private final ReaderServiceImpl readerService;


    @Autowired
    public ReaderController(ReaderServiceImpl readerService) {
        this.readerService = readerService;
    }


    @PostMapping("/borrowBook")
    Result<String> borrowBook(@RequestBody Map<String, String> params) {
        return readerService.borrowBook(params);
    }

    @PostMapping("/returnBook")
    Result<String> returnBook(@RequestBody Map<String, String> params) {
        return readerService.returnBook(params);
    }

    @PostMapping("/findBook")
    public Result<List<Book>> findBook(@RequestParam int current, int size, String name) {
        return readerService.findBook(current, size, name);
    }

    @PostMapping("/getHistory")
    public Result<List<ReadHistory>> getHistory(@RequestBody Map<String, String> params) {
        return readerService.getReadHistory(params);
    }

    @PostMapping("/someReader")
    public Result<Reader> someReader(@RequestParam int id) {
        return readerService.someReader(id);
    }

    @PostMapping("/changeReader")
    public Result<String> changeReader(@RequestBody Reader reader) {
        return readerService.changeReader(reader);
    }

    @PostMapping("/changePassword")
    public Result<String> changePassword(@RequestParam int id, String oldPassword, String newPassword) {
        return readerService.changePassword(id, oldPassword, newPassword);
    }

    @PostMapping("/login")
    public Result<String> login(@RequestParam String account, String password) {
        return readerService.login(account, password);
    }

    @PostMapping("/register")
    public Result<String> register(String account, String password, String name) {
        return readerService.register(account, password, name);
    }
}
